package com.mxf.miaosha.service;

import com.mxf.miaosha.VO.GoodsVO;
import com.mxf.miaosha.dao.GoodsDao;
import com.mxf.miaosha.domain.MiaoshaGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsService {

    @Autowired
    private GoodsDao goodsDao;

    public List<GoodsVO> listGoodsVO() {
        return goodsDao.listGoodsVO();
    }

    public GoodsVO getGoodsVOByGoodsId(long id) {
        return goodsDao.getGoodsVOByGoodsId(id);
    }

    public boolean reduceStock(GoodsVO goodsVO) {
        MiaoshaGoods miaoshaGoods = new MiaoshaGoods();
        miaoshaGoods.setGoodsId(goodsVO.getId());
        int result = goodsDao.reduceStock(miaoshaGoods);
        return result > 0;
    }
}
